﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;

namespace RESTAURANT
{
    public class MyServerConfig
    {
        private static String _filename = null;

        public static String Filename
        {
            get { return MyServerConfig._filename; }
            set { MyServerConfig._filename = value; }
        }
        private static XmlDocument xmlDocument = null;

        private static String IpAddress = "";
        public static String SIpAddress
        {
            get { return MyServerConfig.IpAddress; }
            set { MyServerConfig.IpAddress = value; }
        }

        private static int PortNumber = 5005;
        public static int SPortNumber
        {
            get { return MyServerConfig.PortNumber; }
            set { MyServerConfig.PortNumber = value; }
        }

        private static int PassWord = 0;
        public static int SPassWord
        {
            get { return MyServerConfig.PassWord; }
            set { MyServerConfig.PassWord = value; }
        }

        public static void InitServer(String filename)
        {
            Filename = filename;
            try
            {
                xmlDocument = new XmlDocument();
                xmlDocument.Load(Filename);
                XmlNode eIpAddress = xmlDocument.GetElementsByTagName("IPADDRESS")[0];
                XmlNode ePortNumber = xmlDocument.GetElementsByTagName("PORTNUMBER")[0];
                XmlNode ePassWord = xmlDocument.GetElementsByTagName("PASSWORD")[0];
                IpAddress = eIpAddress.InnerText;
                PortNumber = Convert.ToInt32(ePortNumber.InnerText);
                PassWord = Convert.ToInt32(ePassWord.InnerText);
            }
            catch 
            {
            }
        }
    }
}
